//
// Created by gogoqiu on 2021/10/21.
//

#ifndef RAPIDSVN_CMAKE_REPOPUSH_H
#define RAPIDSVN_CMAKE_REPOPUSH_H

#include <action.hpp>
#include <action_worker.hpp>
#include "wx/wx.h"
#include "jsoncpp/json/json.h"

class MyTagApp;

//Action
//parse the responseText
//on what status
//main_frame满足什么接口？on error response
//on http error
//position fragment
//forward, 本地端口投射到远端端口
//md5, md4
//远端端口投射到本地端口
class RepoPushAction: public NormalAction {
public:
    RepoPushAction( MyTagApp* myTagApp, wxFrame * parent );
    bool Prepare() override;
    bool Perform() override;

protected:
    //int len;
private:

    static int respLength;
    static char* responseText;

    //ssh
    void pushFile ( int fd );

    int saveInfo( const char* url );

    int count;

    static size_t accumulate(void* buffer,size_t size,size_t num_mem_byte,void *stream/** ignore **/);
};

/*
 * 线程内信息
 */
class RepoPushThread: public wxThread{
    wxWindow * parent;
    Tracer * tracer;
    ActionState state;
    ActionResult result;
    MyTagApp* myTagApp;

    NormalAction *action;

public:
    /*
     * ui改善
     * 如何
     * json
     * 当前位置
     * 能够解析到什么位置
     */
    explicit RepoPushThread(MyTagApp* myTagApp1, wxWindow* parent,
            Tracer * tracer, NormalAction* action1 ){
        this->myTagApp = myTagApp1;
        this->parent = parent;
        this->tracer = tracer;
        this->action = action1;
    }

    //
    void * Entry() override;

    //ActionEvent action;
    void ExecuteAction();

    void DeleteAction();

    void TraceError ( const wxString & message ) const;
};

#endif //RAPIDSVN_CMAKE_REPOPUSH_H
